#ifndef __RED_CODE_OBJECT_H__
#define __RED_CODE_OBJECT_H__

#include "rstring.h"
#include "bytecode.h"
#include "redobject.h"

typedef struct _RedCodeObject
{
	RedObject_HEAD

	int			 co_size;
	bytecode_t	*co_buffer;

	RedObject	*co_args;
	RedObject	*co_frees;
	RedObject	*co_vararg;

	RedObject	*co_fname;
	RedObject	*co_source;
	RedObject	*co_module;
} RedCodeObject;

RED_EXPORT extern RedTypeObject RedType_Code;

#define RedCode_Exact(o)		((o)->ob_type == &RedType_Code)

#define RedCode_Size(o)			(((RedCodeObject *)(o))->co_size)
#define RedCode_Buffer(o)		(((RedCodeObject *)(o))->co_buffer)

#define RedCode_Args(o)			(((RedCodeObject *)(o))->co_args)
#define RedCode_Frees(o)		(((RedCodeObject *)(o))->co_frees)
#define RedCode_VarArg(o)		(((RedCodeObject *)(o))->co_vararg)

#define RedCode_Fname(o)		(((RedCodeObject *)(o))->co_fname)
#define RedCode_Module(o)		(((RedCodeObject *)(o))->co_module)
#define RedCode_Source(o)		(((RedCodeObject *)(o))->co_source)

RED_EXPORT void RedCode_LoadSource(RedObject *self, rstring_t *source, RedObject *module);
RED_EXPORT RedObject *RedCode_WrapBytecode(rstring_t *fname, bytecode_t *code, int size);

#endif /* __RED_CODE_OBJECT_H__ */
